package com.Util;

import com.DAO.Menberinfo;
import com.DAO.Roominfo;
import com.DAO.Roomtypeinfo;
import com.DAO.Userinfo;
import com.Module.Menber;
import com.Module.Room;
import com.Module.RoomType;
import com.Module.User;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.util.List;

public class Jpaneltest {
    public JPanel getRoom(){
        JPanel jp=new JPanel();
        Roominfo roominfo=new Roominfo();
        roominfo.select();
        List<Room> list=roominfo.list;
        Room room=list.get(0);
        Object[][] rowDate={{room.getRoomid(),room.getRoomtype(),room.getStreet()==1?"是":"否",room.getRstste()==1?"不可住":"可住",room.getCurrpeople()}};
        Object[] clounm={"房间号","房间类型","是否临街","状态","床位数"};
        DefaultTableModel defaultTableModel=new DefaultTableModel(rowDate,clounm);
        JTable jTable=new JTable();
        jTable.setModel(defaultTableModel);
        for (int i = 1; i < list.size(); i++) {
            Room room1=list.get(i);
            Object[] row={room1.getRoomid(),room1.getRoomtype(),room1.getStreet()==1?"是":"否",room1.getRstste()==1?"不可住":"可住",room1.getCurrpeople()};
            defaultTableModel.addRow(row);
        }
        jTable.setModel(defaultTableModel);
        JScrollPane scrollPane = new JScrollPane(
                jTable,
                ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER
        ){
            @Override
            public Dimension getPreferredSize() {
                return new Dimension(700,450);
            }
        };
        jp.add(scrollPane);
        return jp;
    }
    public JPanel getRoomtype(){
        JPanel jp=new JPanel();
        Roomtypeinfo roomtypeinfo=new Roomtypeinfo();
        roomtypeinfo.select();
        List<RoomType> list=roomtypeinfo.list;
        RoomType roomType=list.get(0);
        Object[][] rowDate={{roomType.getRoomtype(),roomType.getBednumber(),roomType.getPrice()}};
        Object[] clounm={"房间类型","床位数","价格"};
        DefaultTableModel defaultTableModel=new DefaultTableModel(rowDate,clounm);
        JTable jTable=new JTable();
        jTable.setModel(defaultTableModel);
        for (int i = 1; i < list.size(); i++) {
            RoomType room1=list.get(i);
            Object[] row={room1.getRoomtype(),room1.getBednumber(),room1.getPrice()};
            defaultTableModel.addRow(row);
        }
        jTable.setModel(defaultTableModel);
        JScrollPane scrollPane = new JScrollPane(
                jTable,
                ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER
        ){
            @Override
            public Dimension getPreferredSize() {
                return new Dimension(700,400);
            }
        };
        jp.add(scrollPane);
        return jp;
    }
    public JPanel getUser(){
        JPanel jp=new JPanel();
        Userinfo userinfo=new Userinfo();
        userinfo.select();
        List<User> list=userinfo.list;
        User user=list.get(0);
        Object[][] rowDate={{user.getId(),user.getName(),user.getPassword(),user.getTel()}};
        Object[] clounm={"编号","姓名","密码","电话"};
        DefaultTableModel defaultTableModel=new DefaultTableModel(rowDate,clounm);
        JTable jTable=new JTable();
        jTable.setModel(defaultTableModel);
        for (int i = 1; i < list.size(); i++) {
            User user1=list.get(i);
            Object[] row={user1.getId(),user1.getName(),user1.getPassword(),user.getTel()};
            defaultTableModel.addRow(row);
        }
        jTable.setModel(defaultTableModel);
        JScrollPane scrollPane = new JScrollPane(
                jTable,
                ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER
        ){
            @Override
            public Dimension getPreferredSize() {
                return new Dimension(700,450);
            }
        };
        jp.add(scrollPane);
        return jp;
    }
    public JScrollPane getMenber(){
        Menberinfo menberinfo=new Menberinfo();
        menberinfo.select();
        List<Menber> list=menberinfo.list;
        Menber menber=list.get(0);
        Object[][] rowDate={{menber.getMid(),menber.getMname(),menber.getMnumber(),menber.getRoomid(),menber.getRentmoney(),menber.getIndate(),menber.getEnddate()}};
        Object[] cloumnname={"序号","姓名","身份证号","房号","押金","入住时间","退房时间"};
        DefaultTableModel defaultTableModel=new DefaultTableModel(rowDate,cloumnname);
        JTable jTable=new JTable();
        jTable.setModel(defaultTableModel);
        for (int i = 1; i < list.size(); i++) {
            Menber menber1=list.get(i);
            Object[] row = {menber1.getMid(),menber1.getMname(),menber1.getMnumber(),menber1.getRoomid(),menber1.getRentmoney(),menber1.getIndate(),menber1.getEnddate()};
            defaultTableModel.addRow(row);
        }
        jTable.setModel(defaultTableModel);
        JScrollPane scrollPane = new JScrollPane(
                jTable,
                ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER
        ){
            @Override
            public Dimension getPreferredSize() {
                return new Dimension(700,450);
            }
        };
        return  scrollPane;
    }
}